//
//  TagView.m
//  KeleAppProject
//
//  Created by Cen Zhou on 2018/1/15.
//  Copyright © 2018年 Cen Zhou. All rights reserved.
//

#import "TagView.h"
#import "EdgeLabel.h"
@interface TagView()

@property (nonatomic, strong) NSMutableArray *tagsArray;
@end


@implementation TagView

- (void)addTagViewWithDataArray:(NSArray *)dataArray{
    
//    UIView *backCellView = [[UIView alloc] init];
//    backCellView.backgroundColor = [UIColor whiteColor];
//    [self addSubview:backCellView];
//    [backCellView mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(self);
//    }];
    
    for (NSInteger i = 0; i < dataArray.count; i++) {
        
        UIButton *tagLabel = [UIButton buttonWithType:UIButtonTypeCustom];
        
        tagLabel.layer.masksToBounds = YES;
        tagLabel.layer.cornerRadius = 4*WIDTH;
        tagLabel.layer.borderWidth = 1;
        tagLabel.layer.borderColor = KLColor_B10.CGColor;
        tagLabel.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12*WIDTH];
        [tagLabel setTitleColor:KLColor_B8 forState:UIControlStateNormal];
        [tagLabel setTitle:dataArray[i] forState:UIControlStateNormal] ;
        tagLabel.titleLabel.textAlignment = NSTextAlignmentCenter;
        tagLabel.contentEdgeInsets = UIEdgeInsetsMake(3, 10, 3, 10);
        [self addSubview:tagLabel];
        [tagLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            if (i == 0) {
                make.left.equalTo(self).offset(15*WIDTH);
            }else{
                UIButton *tempLabel = self.tagsArray[i - 1];
                make.left.equalTo(tempLabel.mas_right).offset(5*WIDTH);
            }
            
            if (tagLabel.titleLabel.text.length == 2) {
                make.width.mas_equalTo(47*WIDTH);
            }else if (tagLabel.titleLabel.text.length == 3){
                make.width.mas_equalTo(60*WIDTH);
            }else if (tagLabel.titleLabel.text.length == 4){
                make.width.mas_equalTo(74*WIDTH);
            }
        }];
        [self.tagsArray addObject:tagLabel];
    }
}

- (NSMutableArray *)tagsArray{
    if (!_tagsArray) {
        _tagsArray = [NSMutableArray array];
    }
    return _tagsArray;
}

@end
